#include<bits/stdc++.h>
//fangweibiaoqian
#define int long long
using namespace std;
const int N=1e5+5;
int t,n,m,a[N],c[N],x0,x1,x2,x3,k,w=1;
string s;
signed main(){
	freopen("arena.in","r",stdin);
	freopen("arena.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	cin>>n>>m;
	for(int i=1;i<=n;i++) cin>>a[i];
	for(int i=1;i<=m;i++) cin>>c[i];
	while(w<n){
		w*=2;
		k++;
	}
	while(k--) cin>>s;
	cin>>t;
	while(t--){
		cin>>x0>>x1>>x2>>x3;
		cout<<x0+x1+x2+x3<<"\n";
	}
    return 0;
}
